import React, { Component } from 'react'
import { Layout, Menu } from 'antd';
import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons';
import  {withRouter} from 'react-router-dom';
import  sideArr from './asideData/AdminAuthor';
const { Sider } = Layout;
const { SubMenu } = Menu;
class Myside extends Component {
    handlePush =({ keyPath})=>{
         
                 let key = keyPath[0];
                 let subKey  = keyPath[1];
                 if(subKey){
                     localStorage.setItem('subKey',subKey);
                 }
                 this.props.history.push(key);
          
    }
    renderSide=()=>{
       return  sideArr.map(item=>{
              let {key,label,title,children,icon,subKey} = item;
              if(!children){
                  return <Menu.Item key={key}>{label}</Menu.Item>
              }
              return <SubMenu key={subKey} icon={icon} title={title}>
                {children.map(obj=>{
                    return   <Menu.Item key={obj.key}>{obj.label}</Menu.Item>
                })}         
            </SubMenu> 
         })
    }
    componentWillUnmount(){
         localStorage.removeItem('subKey');
    }
    render() {
        // 当前选择的项
        const  curPath = this.props.location.pathname;
        // 当前展开
        const  defaultKey = localStorage.getItem('subKey');
        return (
            <Sider width={200} className="site-layout-background">
              <Menu
                mode="inline"
                defaultSelectedKeys={[curPath]}
                defaultOpenKeys={[ defaultKey ]}
                style={{ height: '100%', borderRight: 0 }}
                onClick={this.handlePush}
              
              >
                  {this.renderSide()}
                    {/* <Menu.Item key="/home/orders">订单</Menu.Item>
                  <Menu.Item key="/home/index">首页</Menu.Item>
                <SubMenu key="sub1" icon={<UserOutlined />} title="账号管理">
                  <Menu.Item key='/home/accountList'>账号列表</Menu.Item>
                  <Menu.Item key='/home/addAccount'>添加账号</Menu.Item>
             
                </SubMenu>
                <SubMenu key="sub2" icon={<LaptopOutlined />} title="商品管理">
                  <Menu.Item key="/home/GoodsList">商品列表</Menu.Item>
                  <Menu.Item key="/home/addGoods">添加商品</Menu.Item>          
                </SubMenu> */}
              </Menu>
            </Sider>
          
        )
    }
}
export default withRouter(Myside);
